package ar.mobileideas.mobiletasks.app.ui;

import ar.mobileideas.mobiletasks.app.main.MobileTasks;
import ar.mobileideas.mobiletasks.resources.resourcesResource;
import net.rim.device.api.i18n.ResourceBundle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.MainScreen;

/**
 * A class extending the MainScreen class, which provides default standard
 * behavior for BlackBerry GUI applications.
 */
public final class HomeScreen extends MainScreen
{
	private static ResourceBundle _resources = ResourceBundle.getBundle(resourcesResource.BUNDLE_ID,resourcesResource.BUNDLE_NAME);
	private MobileTasks app;
    /**
     * Creates a new HomeScreen object
     */
	ButtonField openTasksButton = new ButtonField(_resources.getString(resourcesResource.HomeScreenOpenTasks));
	ButtonField tasksInProgressButton = new ButtonField(_resources.getString(resourcesResource.HomeScreenTasksInProgress));
	ButtonField exitButton = new ButtonField(_resources.getString(resourcesResource.HomeScreenExit));
    
	public HomeScreen()
    {        
        // Set the displayed title of the screen       
        this.setTitle("Mobile Task Manager");
        tasksInProgressButton.setChangeListener(tasksInProgressButtonListener);
        openTasksButton.setChangeListener(openTasksButtonListener);
        this.add(openTasksButton);
        this.add(tasksInProgressButton);
        
        this.add(exitButton);
    }
	
	FieldChangeListener tasksInProgressButtonListener = new FieldChangeListener() {
        
    	public void fieldChanged(Field field, int context) {
    		app = (MobileTasks)UiApplication.getUiApplication();
    		TasksScreen tasksScreen = new TasksScreen(_resources.getString(resourcesResource.TaskScreenTitleInProgress));
    		
    		app.pushScreen(tasksScreen);
        }
    };
    
    FieldChangeListener openTasksButtonListener = new FieldChangeListener() {
        
    	public void fieldChanged(Field field, int context) {
    		app = (MobileTasks)UiApplication.getUiApplication();
    		TasksScreen tasksScreen = new TasksScreen(_resources.getString(resourcesResource.TaskScreenTitleOpen));
    		
    		app.pushScreen(tasksScreen);
        }
    };
}
